package org.blade.personal.manager.sys.corncre;

import java.util.List;

import javax.annotation.Resource;

import org.blade.personal.dao.sys.UserDao;
import org.blade.personal.manager.sys.UserManager;
import org.blade.personal.mode.sys.SystemUser;
import org.blade.personal.utils.Pager;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service("userManager")
@Transactional("transactionManager")
public class UserManagerImpl implements UserManager {

	@Resource
	private UserDao userDao;

	@Override
	public void saveUser(SystemUser u) {
		userDao.add(u);
	}

	@Override
	public void updateUser(SystemUser u) {
		userDao.update(u);
	}

	@Override
	public int deleteUser(SystemUser u) {
		return userDao.delete(u.getId());
	}

	@Override
	public void  pagination(Pager<SystemUser> page, SystemUser user) {
		this.userDao.pagination(page,user);
	}
	
	
	@Override
	public SystemUser getUserByNameAndPassword(String name, String password) {
		String querySql = " select su from SystemUser su where su.name = ? and su.password = ?";
		return userDao.queryForOne(querySql,new Object[]{name,password});
	}
	
	@Override
	public int getUserCountByName(String name) {
		String querySql = " select count(1) from sys_usr where name = '" + name +"'";
		return userDao.getCount(querySql);
	}
	
	@Override
	public SystemUser getById(Long id) {
		return userDao.queryOne(id);
	}
	
	@Override
	public List<SystemUser> getAllUsers() {
		return userDao.getAllUser();
	}
}
